package codeTop;

import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

public class q958 {
    public boolean isCompleteTree(TreeNode root) {
        TreeNode[] tree = new TreeNode[100];
        tree[0] = root;
        Queue<Integer> queue = new LinkedList<>();
        queue.add(0);
        while (!queue.isEmpty()) {
            Integer poll = queue.poll();
            TreeNode node = tree[poll];
            if (node.left != null) {
                if (tree[poll * 2] == null) {
                    return false;
                }
                tree[poll*2+1] = node.left;
                queue.add(poll*2+1);
            }
            if (node.right != null) {
                if (tree[poll * 2+1] == null) {
                    return false;
                }
                tree[poll*2+2] = node.right;
                queue.add(poll*2+2);
            }
        }
        return true;
    }
}
